﻿package foli
{
	import foli.Gallery;
	import foli.GalleryEvent;
	import foli.Album;
	import foli.Line;
	
	import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.materials.ColorMaterial;
	
	public class Board extends DisplayObject3D
	{
		static var width: int = 1200;
		static var height: int = 1000;
		
		public function Board( g: Gallery )
		{
			super();			
			
			// listen to gallery updates 
			g.addEventListener(GalleryEvent.ALBUM_ADDED, this.handleAlbumAdded);			
			
			// create graphical representation 
			addChild( createVisual() );
		}
		
		private function createVisual(): DisplayObject3D
		{
			var p: Plane = new Plane( new ColorMaterial(0xaaaaaa), width, height, width/100, height/100 );
			return p;
		}
		
		private function handleAlbumAdded( e: GalleryEvent )
		{			
			addLine( new Line(e.album) );
		}
		
		private function addLine( l: Line )
		{
			// move down the line a bit
			l.y = (Line.height+2*5)*this.numChildren - height*0.5;
			l.z = -20;
			
			
			addChild(l);
		}
	}	
}